package com.itbour.web.action.trade;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.itbour.com.page.Page;
import com.itbour.common.base.BaseAction;
import com.itbour.common.util.StringUtils;
import com.itbour.dto.com.UserInfoDto;
import com.itbour.dto.trade.PayInfoDto;
import com.itbour.service.trade.PaymentHisInfoService;
import com.opensymphony.xwork2.ActionContext;

/**
 * 支付结果纪录（微信／支付宝等） //DB表itb_payment_his
 * 类型:10商品订单,20发票,30购买模版,40虚拟商品(如vip),50秒杀订单
 * trade_obj_id/交易对象id：订单id，发票id等
 * trade_obj_no/交易对象编号
 * @author 李琦  2017
 */
public class GetPaymentHisInfoAction extends BaseAction{

	/**
	 */
	private static final long serialVersionUID = 1L;
	private PaymentHisInfoService paymentHisInfoService;
	private HashMap<String, Object> resMap = new HashMap<String, Object>();
	private List<PayInfoDto> listRPay;
	private String findTmplId;//交易对象编号
	private String findObjId;//交易对象ID
	private String findHisId;//支付记录ID
	private String findType;//支付东西分类
	private String findPayPf;//支付平台分类
	private String findDateStart;//起始时间
	private String findDateEnd;//结束时间
	
	public String pageListPaymentHisInfo(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto)session.get("user");
		HttpServletRequest request = ServletActionContext.getRequest();
		Integer pageNo = Integer.parseInt(request.getParameter("page"));
		Integer pageSize = Integer.parseInt(request.getParameter("rows"));
		if(user!=null && user.getUser_id()!=null && pageNo!=null && pageSize!=null){
			Map<String, Object> parm = new HashMap<String, Object>();
			if(StringUtils.isNotEmpty(findDateEnd)){//结束时间
				parm.put("endTime",findDateEnd);
			}
			if(StringUtils.isNotEmpty(findDateStart)){//起始时间
				parm.put("startTime",findDateStart);
			}
			if(StringUtils.isNotEmpty(findPayPf)){//支付平台分类
				parm.put("pay_platform",findPayPf);
			}
			if(StringUtils.isNotEmpty(findType)){//支付东西分类
				parm.put("type",findType);
			}
			if(StringUtils.isNotEmpty(findHisId)){//支付记录ID
				parm.put("his_id",findHisId);
			}
			if(StringUtils.isNotEmpty(findTmplId)){//支付交易对象编号
				parm.put("trade_obj_no",findTmplId);
			}
			if(StringUtils.isNotEmpty(findObjId)){//支付交易对象编号
				parm.put("trade_obj_id",findObjId);
			}
			Page page = paymentHisInfoService.pagePaymentHisInfo(parm, pageNo, pageSize);
			resMap.put("total", page.getTotalCount());
			resMap.put("rows", page.getResult());
		}
		return SUCCESS;
	}
	
	//获取支付返回信息详情
	public String getPayReturnInfo(){
		Map<String, Object> session = ActionContext.getContext().getSession();
		UserInfoDto user = (UserInfoDto)session.get("user");
		if(user!=null && user.getUser_id()!=null){
			HttpServletRequest request = ServletActionContext.getRequest();
			Integer hisId = Integer.parseInt(request.getParameter("hisId"));
			if(hisId!=null){
				Map<String, Object> parm = new HashMap<String, Object>();
				parm.put("his_id",hisId);
				listRPay=paymentHisInfoService.getPayReturnInfo(parm);
			}
		}
		return SUCCESS;
	}

	
	
	public PaymentHisInfoService getPaymentHisInfoService() {
		return paymentHisInfoService;
	}
	public void setPaymentHisInfoService(PaymentHisInfoService paymentHisInfoService) {
		this.paymentHisInfoService = paymentHisInfoService;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public HashMap<String, Object> getResMap() {
		return resMap;
	}
	public void setResMap(HashMap<String, Object> resMap) {
		this.resMap = resMap;
	}

	public List<PayInfoDto> getListRPay() {
		return listRPay;
	}
	public void setListRPay(List<PayInfoDto> listRPay) {
		this.listRPay = listRPay;
	}

	public String getFindTmplId() {
		return findTmplId;
	}

	public void setFindTmplId(String findTmplId) {
		this.findTmplId = findTmplId;
	}

	public String getFindHisId() {
		return findHisId;
	}

	public void setFindHisId(String findHisId) {
		this.findHisId = findHisId;
	}
	public String getFindType() {
		return findType;
	}
	public void setFindType(String findType) {
		this.findType = findType;
	}
	public String getFindPayPf() {
		return findPayPf;
	}
	public void setFindPayPf(String findPayPf) {
		this.findPayPf = findPayPf;
	}

	public String getFindDateStart() {
		return findDateStart;
	}

	public void setFindDateStart(String findDateStart) {
		this.findDateStart = findDateStart;
	}
	public String getFindDateEnd() {
		return findDateEnd;
	}
	public void setFindDateEnd(String findDateEnd) {
		this.findDateEnd = findDateEnd;
	}
	public String getFindObjId() {
		return findObjId;
	}
	public void setFindObjId(String findObjId) {
		this.findObjId = findObjId;
	}
	
}
